import { goodsForHome } from "../../../data/goods";
let interval;
let tar = new Date().getTime() + 1000*3600*32;//new Date("2023-07-30 16:07:55");
Page({
  data: {
    leftTime:'',
    isLoading: true,
    goods: [],
  },
  onLoad(){
    interval=setInterval(()=>(this.showTime(this)),1000);
    //
    this.setData({goods:goodsForHome()});
    setTimeout(()=>{
      this.setData({isLoading:false});
    },500);
  },
  onUnload(){
    clearInterval(interval);
  },
  showTime(that) {
    let now = new Date();
    let second = (tar - now)/1000;
    //let second =  3600*36;
    //
    var day = Math.floor(second / 3600 / 24);
    var dayStr = day.toString();
    if (dayStr.length == 1) dayStr = '0' + dayStr;
    //
    var hr = Math.floor((second - day * 3600 * 24) / 3600);
    var hrStr = hr.toString();
    if (hrStr.length == 1) hrStr = '0' + hrStr;
    //
    // 分钟位
    var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
    var minStr = min.toString();
    if (minStr.length == 1) minStr = '0' + minStr;
    // 秒位
    var sec = Math.floor(second - day * 3600 * 24 - hr * 3600 - min * 60);
    var secStr = sec.toString();
    if (secStr.length == 1) secStr = '0' + secStr;
    // timeCountDown
    let timeStr = dayStr + "天 " + hrStr + ":" + minStr + ":" + secStr;
    that.setData({leftTime:timeStr});
  },
  showRule() {
    wx.showToast({
      title: '规则详情',
    })
  }
})